class Solution:
    def longestPalindrome(self, s: str) -> str:
        candidate=""
        queue=s[:2]
        length=len(s)
        if length==1 or length==0 or (length==2 and s[0]==s[1]):
            return s
        def findpali(index,offset):
            for i in range(len(queue)-offset):
                if index+i>=length or queue[-i-1-offset]!=s[index+i]:
                    i-=1
                    break
            return queue[-i-1-offset:]+s[index:index+i+1]
        for c in range(2,len(s)):
            if s[c]==queue[-1]:
                res=findpali(c,0)
                if len(res)>len(candidate):
                    candidate=res
            if s[c]==queue[-2]:
                res=findpali(c,1)
                if len(res)>len(candidate):
                    candidate=res  
            queue+=s[c]
        if candidate=="":
            if s[0]==s[1]:
                return s[:2]
            return s[0]
        return candidate

s=Solution()
print(s.longestPalindrome("ccd"))